package com.mudingkou.mos.common.util;

import org.springframework.boot.system.ApplicationHome;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * 服务器辅助
 *
 * @author kzc
 * @date 2021/08/17
 */
public class BootUtil {
    public static String getHomePath() {
        File path = null;
        try {
            path = new File(ResourceUtils.getURL("classpath:").getPath());
            if (!path.exists()) {
                path = new File("");
            }
            ;
        } catch (FileNotFoundException e) {
            //
        }
        if (path == null) {
            return getHomePathOrigin();
        } else {
            return path.getAbsolutePath();
        }
    }

    public static String getHomePathOrigin() {
        ApplicationHome home = new ApplicationHome(BootUtil.class);
        return home.getDir().getAbsolutePath();
    }
}
